'use strict';

var mongoose = require('mongoose'),
    Book = mongoose.model('Books');
//读取全部书籍
exports.all_books = function(req, res) {
        Book.find ({}, function(err, book) {
            if (err)
            res.send(err);
            res.json(book);
        });
};
//新建书籍
exports.create_book = function(req, res) {
     var new_book = new Book(req.body);
     new_book.save(function(err, book) {
         if (err)
         res.send(err);
         res.json(book);
     });
};

//读取书籍的id
exports.read_book = function(req, res) {
     Book.findById(req.params.bookId, function(err, book) {
         if (err)
         res.send(err);
         res.json(book);
     });
};